import React from 'react';
import { Button } from 'antd';
import Modal from '../../../../../../components/Modal';
import CommonList from '../../../../../../components/CommonLists/list';
import VersionDetail from './versionDetail';
import VersionSwitch from './versionSwitch';

class PublishHistoryList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'history';
    this.btnGroup = [
      (record) => (
        <Button type='link' onClick={() => this.handleDetail(record)}>
          查看
        </Button>
      ),
      (record) => {
        const { status } = record;
        return (
          !status && (
            <Button type='link' onClick={() => this.handleSwitch(record)}>
              切换此版本
            </Button>
          )
        );
      },
    ].filter(Boolean);
  }

  handleDetail(record) {
    Modal.open({
      title: '接口信息',
      width: '1000px',
      content: <VersionDetail record={record} />,
      isOkBtn: false,
      maskClosable: false,
      isCancelBtn: false,
    });
  }

  handleSwitch(record) {
    Modal.open({
      title: '接口版本切换',
      width: '500px',
      content: <VersionSwitch {...this.props} record={record} closeModal={() => Modal.close()} />,
      isOkBtn: false,
      maskClosable: false,
      isCancelBtn: false,
    });
  }
}

export default PublishHistoryList;
